//199000912邹星宇
var ad_width="100px";
var ad_height="250px" ;
var ad_img="img/ad1.jpg" ;
var close_img="img/close.png" ;
var xia_width="300px";
var xia_height="250px" ;
var xia_img="img/ad2.jpg" ;
//左右侧广告div容器
function showAd(weizhi){
			var ad_left = document.createElement( "div");
			ad_left.style.width = ad_width;
			ad_left.style.height = ad_height;
			ad_left.style.padding = "0px" ;
			ad_left.style.position = "absolute";
			if(weizhi=="left"){
				ad_left.style.left = "30px";
			}else if(weizhi=="right"){
				ad_left.style.right = "30px";
			}
			
			ad_left.style.top = "20px";
			
			//图片
			var adimg=document.createElement( "img" );
			adimg.src=ad_img;
			ad_left.appendChild(adimg);
			//关闭按钮
			var closeimg = document.createElement( "img" );
			closeimg.src = close_img;
			closeimg.style.width = "50px" ;
			closeimg.style.position="relative";
			if(weizhi=="left"){
				closeimg.style.left="50px" ;
			}else if(weizhi=="right"){
				closeimg.style.left="0px" ;
			}
			
			closeimg.style.top="-20px";
			closeimg.style.cursor = "pointer" ;
			ad_left.appendChild(closeimg);
			//将ad_left添加到html中
			document.documentElement.appendChild(ad_left);
			//为关闭按钮注册单击事件，实现关闭广告功能
			closeimg.addEventListener( "click",function( ){
				this.parentNode.style.display="none" ;
			})
			//编写代码，实现对联广告随滚动条移动。
			// scrollTop:代表由于滚动隐藏的高度
			window.addEventListener( "scroll" ,function(){
			var st1=document.documentElement.scrollTop||document.body.scrollTop;
			ad_left.style.top=(st1+20)+"px" ;
			})
    }
	showAd("left");
	showAd("right");
	//右下角广告的弹出与消失
	//199000912邹星宇
	open();
	var ad_bottom = document.createElement( "div");
	ad_bottom.style.width = xia_width;
	ad_bottom.style.height = xia_height;
	ad_bottom.style.padding = "0px" ;
	ad_bottom.style.position = "absolute";
	ad_bottom.style.right = "30px";
	ad_bottom.style.top = "670px";
	//创建 img 元素，并加入到 ad_bottom 中，作为广告图片
	var adimg=document.createElement( "img" );
	adimg.src=xia_img;
	ad_bottom.appendChild(adimg);
	//创建关闭按钮，并加入到 ad_bottom中
	var closeimg = document.createElement( "img" );
	closeimg.src = close_img;
	closeimg.style.width = "50px" ;
	closeimg.style.position="relative";
    closeimg.style.left="248px" ;
	closeimg.style.top="-255px";
	closeimg.style.cursor = "pointer" ;
	ad_bottom.appendChild(closeimg);
	//自动弹出广告，5秒钟后，将ad_bottom添加到html中
	function open(){
		 time=setInterval("document.documentElement.appendChild(ad_bottom);",5000);
	}
	//打开页面10秒后关闭广告
	var num=10;
	let myset=setInterval(aa,'1000')
	function aa(){
		num--;
		if(num==0){
			ad_bottom.style.display = 'none';
				clearInterval(myset)
		}	
	}	
	//为关闭按钮注册单击事件，实现关闭广告功能
	closeimg.addEventListener( "click",function( ){
		this.parentNode.style.display="none" ;
	})
	//编写代码，实现对联广告随滚动条移动。
	// scrollTop:代表由于滚动隐藏的高度
	window.addEventListener( "scroll" ,function(){
	var st1=document.documentElement.scrollTop||document.body.scrollTop;
	ad_bottom.style.top=(st1+670)+"px" ;
	})
	